package com.jgdt.demo.core;
import android.app.Application;
import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.LifecycleOwner;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.Observer;

public class IViewModel extends AndroidViewModel {
    public final MutableLiveData<Message> RESULT = new MutableLiveData<>();

    public IViewModel(Application application) {
        super(application);
        //MediatorLiveData merger=new MediatorLiveData();
        //merger.addSource(model.ERROR, (error)->{merger.postValue(error);});
        //merger.addSource(model.USER, (error)->{merger.postValue(error);});
    }
    public void dispatchMessage(int msgId, int result, Object data) {
        RESULT.postValue(new Message(msgId,result,data));
    }
    public void observe(LifecycleOwner owner, Observer<Message> observer) {
        RESULT.observe(owner, observer);
    }

    public static class Message<T> {
        public final int msgId;
        public final int result;
        public final T data;
        public Message(int msgId, int result, T data) {
            this.msgId = msgId;
            this.result = result;
            this.data = data;
        }
    }
}